﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FazaDemo.BL.DataAccess;
using FazaDemo.BL.SubDomains;
using FazaDemo.Data;

namespace FazaDemo.BL.Services
{
    public class MenuLoader : IMenuLoader
    {

        private readonly IRepository<TS_SYS_EC_MENU, Tuple<string, int>> repository;

        public MenuLoader()
        {
            repository =
                new EntityRepository<TS_SYS_EC_MENU, Tuple<string, int>>();
        }

        public IEnumerable<MenuItem> LoadMenu()
        {
            IList<TS_SYS_EC_MENU> loadingItems = repository.GetAll();
            var converter = new MenuConverter(loadingItems);
            var resultItems = converter.BuildMenuItems();
            var optimiser = new MenuItemsOptimizer(resultItems);
            return optimiser.RestoreItems();
        }
    }
}
